package lv.servidordisqueria.domain;

import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import lv.mensajeriadisqueria.idomain.IAutor;
import lv.mensajeriadisqueria.idomain.IDisco;
import lv.mensajeriadisqueria.idomain.IInterprete;
import lv.mensajeriadisqueria.idomain.ITema;
import lv.mensajeriadisqueria.idomain.ITversion;

/**
 * Es la clase con cual se mapea con la tabla TVERSION de la
 * base de datos
 */
@Entity
@Table(name = "TVERSION")
public class Tversion extends Domain implements ITversion {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = -7698579527020530375L;
	
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "ID_TVERSION")
	private Integer idTversion;
	
	@ManyToOne(targetEntity = Tema.class, fetch = FetchType.LAZY, 
			cascade = {CascadeType.PERSIST, CascadeType.REFRESH, CascadeType.MERGE})
	@JoinColumn(name = "ID_TEMA")
	private ITema tema;
	
    @Column(name="TVERSION")
	private String tVersion;
	
    @Column(name="DURACION")
	private Date duracion;

    @ManyToMany(targetEntity = Musico.class, fetch = FetchType.LAZY,
    		cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
	@JoinTable(name="RELACION_INTERPRETE_VERSION", joinColumns=@JoinColumn(name="ID_TVERSION"),
			inverseJoinColumns=@JoinColumn(name="ID_MUSICO"))
	private List<IInterprete> interpretes;

    @ManyToMany(targetEntity = Musico.class, fetch = FetchType.LAZY,
    		cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
	@JoinTable(name="RELACION_AUTOR_VERSION", joinColumns=@JoinColumn(name="ID_TVERSION"),
			inverseJoinColumns=@JoinColumn(name="ID_MUSICO"))
	private List<IAutor> autores;

    @ManyToMany(targetEntity = Disco.class, fetch = FetchType.LAZY, 
    		cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REFRESH})
	@JoinTable(name="RELACION_VERSION_DISCO", joinColumns=@JoinColumn(name="ID_TVERSION"),
			inverseJoinColumns=@JoinColumn(name="ID_DISCO"))
	private List<IDisco> discos;
	
	public Tversion(){}

	public Tversion(ITema iTema, String version, Date duracion) {
		super();
		this.tema = iTema;
		this.tVersion = version;
		this.duracion = duracion;
	}
	
	public ITema getTema() {
		return tema;
	}

	public void setTema(ITema tema) {
		this.tema = tema;
	}

	public String getTVersion() {
		return tVersion;
	}

	public void setTVersion(String version) {
		tVersion = version;
	}

	public Date getDuracion() {
		return duracion;
	}

	public void setDuracion(Date duracion) {
		this.duracion = duracion;
	}

	@Override
	public List<IAutor> getAutores() {
		return autores;
	}

	@Override
	public List<IInterprete> getInterpretes() {
		return interpretes;
	}

	@Override
	public void setAutores(List<IAutor> autores) {
		this.autores = autores;
	}

	@Override
	public void setInterpretes(List<IInterprete> interpretes) {
		this.interpretes = interpretes;
	}

	@Override
	public List<IDisco> getDiscos() {
		return discos;
	}

	@Override
	public void setDiscos(List<IDisco> discos) {
		this.discos = discos;
	}

	@Override
	public Integer getIdTversion() {
		return idTversion;
	}

	@Override
	public void setIdTversion(Integer idTversion) {
		this.idTversion = idTversion;
	}
}